import { reqGetDestination } from '../../api/destination'
import {
  GET_DESTINATION,
  SET_HOT_INDEX,
  SET_RECOMMEND_INDEX,
  SET_THEME_INDEX,
} from '../../utils/config'

const state = {
  destination: {},
  hotIndex: '1',
  recommendIndex: '1',
  themeIndex: '1',
}
const actions = {
  async getDestination({ commit }) {
    const res = await reqGetDestination()
    commit(GET_DESTINATION, res)
  },
  // 修改热门目的地的下标
  setHotIndex({ commit }, index) {
    commit(SET_HOT_INDEX, index)
  },
  // 修改当季推荐的下标
  setRecommendIndex({ commit }, index) {
    commit(SET_RECOMMEND_INDEX, index)
  },
  // 修改主题精选的下标
  setThemeIndex({ commit }, index) {
    commit(SET_THEME_INDEX, index)
  },
}

const mutations = {
  [GET_DESTINATION](state, data) {
    console.log(data)
    state.destination = data
  },
  [SET_HOT_INDEX](state, index) {
    state.hotIndex = index
  },
  [SET_RECOMMEND_INDEX](state, index) {
    state.recommendIndex = index
  },
  [SET_THEME_INDEX](state, index) {
    state.themeIndex = index
  },
}

const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
}
